#include "mcu_flash.h"
#include "mcu.h"


void OcpFlash_WritePage(u32 page_addr, const void *buff)
{
    uint32_t PAGEError = 0;
    FLASH_EraseInitTypeDef EraseInitStruct={0};

    /* Unlock Flash */
    HAL_FLASH_Unlock();

    EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGEERASE;        /* Page Erase */
    EraseInitStruct.PageAddress = page_addr;            /* Erase start address */
    EraseInitStruct.NbPages  = 1;      /* Page erase Numbers */
    if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK)  /* Page Erase Start */
    {
        Error_Handler();
    }
    if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_PAGE, page_addr, (u32 *)buff) != HAL_OK)/* Program start */
    {
        Error_Handler();         
    }

    /* Lock FLASH */
    HAL_FLASH_Lock();

    // 待添加校验，如果错误重试
}



